﻿using Fluffy.WinForms;
using System;
using System.Windows;

namespace Fluffy.Library.Logging
{
	/// <summary>
	/// Interaction logic for LoggerView.xaml
	/// </summary>
	public partial class LoggerView
	{
		private LoggerView(Exception exception)
		{
			InitializeComponent();

			DataContext = new LoggerViewModel(exception);
			image.Source = IconUtilities.ErrorIcon;
		}

		public static void Log(Exception exception)
		{
			if (exception == null) 
				throw new ArgumentNullException("exception");

			if (Application.Current.MainWindow.IsInitialized)
			{
				Application.Current.Dispatcher.BeginInvoke(new Action(() =>
				{
					LoggerView logger = new LoggerView(exception);
					logger.Owner = Application.Current.MainWindow;
					logger.WindowStartupLocation = WindowStartupLocation.CenterOwner;
					logger.ShowDialog();
				}));
			}
		}
	}
}
